#include "math.h"
double changePhi(double);
double getDPhi(double,double);
double cal_deltaR(double,double,double,double);

double cal_deltaR(double eta1, double phi1, double eta2, double phi2){
    double delEta = eta1-eta2;
    double delPhi = getDPhi(phi1,phi2);
    double deltaR = sqrt(delEta*delEta + delPhi*delPhi);
    return deltaR;
}
double getDPhi(double phi1, double phi2){
    double new_phi1 = changePhi(phi1);
    double new_phi2 = changePhi(phi2);
    if(new_phi1==-99 || new_phi2==-99)return -99;
    double delPhi = changePhi(new_phi1-new_phi2);
    return delPhi;
}
double changePhi(double phi){
    if(phi<-10 || phi>10)return -99;
    const double pi = 3.1416;
    double newPhi = -1;
    if(phi > pi){ 
        newPhi = -2*pi + phi;
    }else if(phi < -3.1416){
        newPhi = phi + 2*pi;
    }else {
        newPhi=phi;
    }
    return newPhi;
}
